// pages/mine/mine.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    orderTypes: [
      {
        id: 1,
        name: '待付款',
        icon: '/assets/icons/unpaid.png',
        count: 0
      },
      {
        id: 2,
        name: '待确认',
        icon: '/assets/icons/unconfirmed.png',
        count: 0
      },
      {
        id: 3,
        name: '待评价',
        icon: '/assets/icons/unrated.png',
        count: 0
      },
      {
        id: 4,
        name: '退款/售后',
        icon: '/assets/icons/refund.png',
        count: 0
      }
    ],
    functionGroups: [
      {
        title: '我的服务',
        items: [
          {
            id: 1,
            name: '我的房屋',
            icon: '/assets/icons/house-active.png',
            url: '/pages/house/my-house/list'
          },
          {
            id: 2,
            name: '我的车位',
            icon: '/assets/icons/parking-active.png',
            url: '/pages/parking/my-parking/list'
          },
          {
            id: 3,
            name: '报修记录',
            icon: '/assets/icons/repair.png',
            url: '/pages/house/repair/list'
          }
        ]
      },
      {
        title: '财务中心',
        items: [
          {
            id: 4,
            name: '电子发票',
            icon: '/assets/icons/invoice.png',
            url: '/pages/finance/invoice/list'
          },
          {
            id: 5,
            name: '支付记录',
            icon: '/assets/icons/payment.png',
            url: '/pages/finance/payment/list'
          }
        ]
      },
      {
        title: '设置',
        items: [
          {
            id: 6,
            name: '个人信息',
            icon: '/assets/icons/sign.png',
            url: '/pages/mine/profile/edit'
          },
          {
            id: 7,
            name: '发票抬头',
            icon: '/assets/icons/invoice.png',
            url: '/pages/mine/invoice-title/list'
          },
          {
            id: 8,
            name: '意见反馈',
            icon: '/assets/icons/feedback.png',
            url: '/pages/mine/feedback/add'
          }
        ]
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getUserInfo()
    this.getOrderCounts()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  getUserInfo() {
    // TODO: 获取用户信息
  },

  getOrderCounts() {
    // TODO: 获取各类订单数量
  },

  onLogin() {
    // TODO: 处理登录逻辑
  },

  viewAllOrders() {
    wx.navigateTo({
      url: '/pages/order/list'
    })
  },

  onOrderTypeClick(e) {
    const { type } = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/order/list?type=${type}`
    })
  },

  onFunctionClick(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({ url })
  }
})